[Ready for review] Adds problem struct, neg and promote atoms and a lot more tests#5
[Ready for review] Adds problem struct, neg and promote atoms and a lot more tests#5Transurgeon merged 31 commits intomainfrom
Conversation
|
I did a quick scan and it looks good. But I want to go through it very carefully once you think it's ready. Add some more tests, and carefully check them. For example, in test_problem.h there seems to be no test for a problem with several constraints. Nice job! |
Transurgeon
left a comment
There was a problem hiding this comment.
I think this is good to go.. many more changes since we last talked, but I have a much better understanding of the tests (I did look at them, finally) and the overall code structure.
Here's the structure:
- test_native.py just tests manual formation of a problem using the python bindings. By manual, I mean trees are formed manually.
- test_unconstrained.py tests the objective and gradient of many different problems.
- test_constrained.py tests the constraint forward and jacobian for many other different problems.
- I also added a few C tests (similar to test_native) and some Claude generated tests for neg and promote (please double check those and the implementations carefully.. they seem fine at first glance, but maybe some subtle errors can be there).
Let's go man! Huge progress today. Next step will be to add the retrieval of LinearOperators and getting them to work.
|
Huge progress man! You're a machine. I left a few comments. Perhaps it's good if you don't add any code with new functionality to this PR. It would be nice to get it merged soon! |
Split Python binding functions into separate header files: - atoms/: one file per atom type (variable, constant, linear, log, exp, add, sum, neg, promote) - problem/: one file per method (make_problem, init_derivatives, objective_forward, constraint_forward, gradient, jacobian) Removed standalone forward/jacobian bindings (use problem_* instead). bindings.c now only contains includes and module definition. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Values are now accessed directly from the problem struct: - prob->constraint_values for constraint forward results - prob->gradient_values for objective gradient - prob->stacked_jac for constraint jacobian Also updated Python bindings and tests to use the new API. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Nice, we're getting there. I left a few easy to fix comments |
- Replace manual loops with memcpy for copying row pointers and column indices in neg.c and promote.c - Move workspace allocation from eval_wsum_hess to wsum_hess_init in promote.c, using memset to zero before use - Remove unused promote_expr struct (had no extra fields beyond base) - Simplify new_promote to use new_expr directly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- promote.c: Use memcpy for wsum_hess values in eval_wsum_hess - problem.c: Simplify row pointer loop to directly copy cjac->p with offset 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@dance858 just committed fixes to your review, thanks again! |
You are a machine man! A well-crafted machine from Canada. Keep the good work up. |
This matches CVXPY's promote atom behavior which only broadcasts scalars to vectors/matrices. Removes vector-to-vector promotion support and the associated dwork allocation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use memcpy instead of loops for copying jacobian indices and values - Use pointer arithmetic style (ptr + offset) instead of &ptr[offset] - Remove unnecessary nnz == 0 guard in jacobian_init - Move jacobian tests from forward_pass/ to jacobian_tests/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Awesome, I'm approving this PR now. Once you have fixed the small comments above, please merge it. Very nice job WZZ!!! |
Remove duplicate function definition that was causing compilation errors, likely introduced during merge from main. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manual element-by-element array assertions with helper functions for cleaner, more maintainable test code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Relocate test_neg_jacobian and test_neg_chain from forward_pass/affine/ to jacobian_tests/ for better test organization. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This PR adds the problem struct. It is currently still in draft mode because I have yet to give a thorough review of what Claude has vibed out. But I think it is mostly in a good state, so I thought you could have a look and give some initial feedback.
I have added your feedback and made sure the problem struct would use pointers for the jacobian, gradient and constraint values. The constraints are stored as a pointer to a pointer.. I think it makes sense, since we want to know where the list begins in memory.
I will also try to cleanup the tests and review them more carefully.
The next step will be to shortcut the expression trees and form the A matrices of affine arguments using the
CoeffExtractor. I had initial doubts that it would work.. but after more thought being put into it I think it will work just fine.My concern was as follows: we might have to build the corresponding
xin\phi(Ax)by retrieving the variables that appear in the tree and zeroing out everything else. However, this is not true, since theAin question is global, the columns of variables that don't appear will already be filled with zeros.. so we can actually replace the entire affine subtree with thisAin the convert method.